import { defineStore } from "pinia";
import type { Asset } from "@/types/Asset";
import { generateId } from "@/utils/tool";
import { Page } from "@/materials/page/Page";
import { Bone } from "@/materials/bone/Bone";
import { Container } from "@/materials/container/Container";
import { Text } from "@/materials/text/Text";
import { Dialog } from "@/materials/dialog/Dialog";
import { Chart } from "@/materials/chart/Chart";
import pageCover from "@/assets/images/page_cover.png";
import boneCover from "@/assets/images/bone_cover.png";
import containerCover from "@/assets/images/container_cover.png";
import textCover from "@/assets/images/text_cover.png";
import dialogCover from "@/assets/images/dialog_cover.png";
import commonChartCover from "@/assets/images/common_chart_cover.png";

export const useAsset = defineStore("asset", {
	state() {
		return {
			assets: [] as Asset[],
		};
	},
	actions: {
		init() {
			this.assets.length = 0;
			this.assets.push({
				id: generateId(),
				title: "文章",
				cover: boneCover,
				categories: ["模版"],
				component: (() => ({
					version: "0.0.1",
					id: "lil8t",
					key: "container",
					title: "文章",
					actived: true,
					nestable: false,
					locked: false,
					hidden: false,
					selectable: true,
					moveable: true,
					resizable: false,
					autoReplace: false,
					autoLayout: true,
					layout: {
						snap: {
							v: [],
							h: [],
						},
						left: 100,
						top: 240,
						width: 300,
						height: 268,
					},
					props: {
						backgroundColor: "#000000",
						title: "标题",
						content: "这是一段文本内容...",
					},
					state: {},
					watchers: [],
					dataSources: [],
					actions: [],
					emits: {
						mounted: {
							executeType: "concurrent",
							timeout: 0,
							actionsName: [],
						},
						beforeUnmount: {
							executeType: "concurrent",
							timeout: 0,
							actionsName: [],
						},
					},
					propsExpression: {},
					stateExpression: {},
					customProps: [
						{
							key: "title",
							label: "标题",
							type: "text",
							options: [],
						},
						{
							key: "content",
							label: "内容",
							type: "text",
							options: [],
						},
					],
					customEmits: [],
					components: [
						{
							version: "0.0.1",
							id: "bd8rj",
							key: "text",
							title: "标题",
							actived: false,
							nestable: false,
							locked: false,
							hidden: false,
							selectable: true,
							moveable: true,
							resizable: true,
							autoReplace: false,
							autoLayout: false,
							layout: {
								snap: {
									v: [],
									h: [],
								},
								left: 0,
								top: 0,
								width: 300,
								height: 40,
							},
							props: {
								content: "标题",
								color: "#ffffff",
								fontSize: 18,
								fontStyle: "normal",
								fontWeight: "bold",
								lineHeight: 40,
								textAlign: "center",
								textDecorationLine: "none",
								backgroundColor: "transparent",
								borderWidth: 0,
								borderColor: "transparent",
								borderStyle: "solid",
								borderRadius: 0,
							},
							state: {},
							watchers: [],
							dataSources: [],
							actions: [],
							emits: {
								click: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								dblclick: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								mounted: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								beforeUnmount: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
							},
							customProps: [],
							customEmits: [],
							components: [],
							propsExpression: {
								content: "parent.props.title",
							},
							stateExpression: {},
						},
						{
							version: "0.0.1",
							id: "rnxg8",
							key: "text",
							title: "内容",
							actived: false,
							nestable: false,
							locked: false,
							hidden: false,
							selectable: true,
							moveable: true,
							resizable: true,
							autoReplace: false,
							autoLayout: false,
							layout: {
								snap: {
									v: [],
									h: [],
								},
								left: 0,
								top: 40,
								width: 300,
								height: 228,
							},
							props: {
								content: "这是一段文本内容...",
								color: "#eeeeee",
								fontSize: 16,
								fontStyle: "normal",
								fontWeight: "normal",
								lineHeight: 30,
								textAlign: "center",
								textDecorationLine: "none",
								backgroundColor: "transparent",
								borderWidth: 0,
								borderColor: "transparent",
								borderStyle: "solid",
								borderRadius: 0,
							},
							state: {},
							watchers: [],
							dataSources: [],
							actions: [],
							emits: {
								click: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								dblclick: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								mounted: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								beforeUnmount: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
							},
							customProps: [],
							customEmits: [],
							components: [],
							propsExpression: {
								content: "parent.props.content",
							},
							stateExpression: {},
						},
					],
				}))(),
			});
			this.assets.push({
				id: generateId(),
				title: "组件通信",
				cover: boneCover,
				categories: ["模版"],
				component: (() => ({
					version: "0.0.1",
					id: "1z52e",
					key: "container",
					title: "组件通信示例",
					actived: true,
					nestable: true,
					locked: false,
					hidden: false,
					selectable: true,
					moveable: true,
					resizable: false,
					autoReplace: false,
					autoLayout: true,
					layout: {
						snap: {
							v: [],
							h: [],
						},
						left: 186,
						top: 217,
						width: 240,
						height: 30,
					},
					props: {
						backgroundColor: "#00000000",
					},
					state: {},
					watchers: [],
					dataSources: [],
					actions: [],
					emits: {
						mounted: {
							executeType: "concurrent",
							timeout: 0,
							actionsName: [],
						},
						beforeUnmount: {
							executeType: "concurrent",
							timeout: 0,
							actionsName: [],
						},
					},
					customProps: [],
					customEmits: [],
					components: [
						{
							version: "0.0.1",
							id: "fsz6y",
							key: "dialog",
							title: "对话框",
							actived: false,
							nestable: true,
							locked: false,
							hidden: false,
							selectable: true,
							moveable: false,
							resizable: false,
							autoReplace: false,
							autoLayout: false,
							props: {
								show: false,
							},
							state: {},
							watchers: [],
							dataSources: [],
							actions: [],
							emits: {
								click: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								dblclick: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								mounted: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								beforeUnmount: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
							},
							customProps: [],
							customEmits: [],
							components: [
								{
									version: "0.0.1",
									id: "cp4n8",
									key: "container",
									title: "容器",
									actived: false,
									nestable: true,
									locked: false,
									hidden: false,
									selectable: true,
									moveable: true,
									resizable: false,
									autoReplace: false,
									autoLayout: true,
									layout: {
										snap: {
											v: [],
											h: [],
										},
										left: 160,
										top: 230,
										width: 100,
										height: 100,
									},
									props: {
										backgroundColor: "#00000000",
									},
									state: {},
									watchers: [],
									dataSources: [],
									actions: [
										{
											name: "action1",
											type: "none",
											changeVisibleParams: {
												targetComponentsId: [],
												visible: "toggle",
											},
											changePropParams: {
												targetComponentId: "t2y2x",
												key: "show",
												expression: "false",
											},
											changeStateParams: {
												targetComponentId: "",
												key: "",
												expression: "",
											},
											requestDataSourceParams: {
												targetComponentId: "",
												name: "",
											},
											triggerOtherActionParams: {
												targetComponentId: "",
												name: "",
											},
											beforeHandler:
												'alert("接收到子组件触发了关闭事件");\nparent.props.show = false;\nreturn true;',
											afterHandler: "",
										},
									],
									emits: {
										mounted: {
											executeType: "concurrent",
											timeout: 0,
											actionsName: [],
										},
										beforeUnmount: {
											executeType: "concurrent",
											timeout: 0,
											actionsName: [],
										},
										close: {
											executeType: "concurrent",
											timeout: 0,
											actionsName: ["action1"],
										},
									},
									propsExpression: {},
									stateExpression: {},
									customProps: [],
									customEmits: [
										{
											key: "close",
											label: "关闭",
										},
									],
									components: [
										{
											version: "0.0.1",
											id: "gyi1g",
											key: "text",
											title: "标题",
											actived: false,
											nestable: false,
											locked: false,
											hidden: false,
											selectable: true,
											moveable: true,
											resizable: true,
											autoReplace: false,
											autoLayout: false,
											layout: {
												snap: {
													v: [],
													h: [],
												},
												left: 0,
												top: 0,
												width: 100,
												height: 30,
											},
											props: {
												content: "提示",
												color: "#ffffff",
												fontSize: 18,
												fontStyle: "normal",
												fontWeight: "bold",
												lineHeight: 30,
												textAlign: "center",
												textDecorationLine: "none",
												backgroundColor: "transparent",
												borderWidth: 0,
												borderColor: "transparent",
												borderStyle: "solid",
												borderRadius: 0,
											},
											state: {},
											watchers: [],
											dataSources: [],
											actions: [],
											emits: {
												click: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
												dblclick: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
												mounted: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
												beforeUnmount: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
											},
											customProps: [],
											customEmits: [],
											components: [],
											propsExpression: {},
											stateExpression: {},
										},
										{
											version: "0.0.1",
											id: "ca0f6",
											key: "text",
											title: "关闭",
											actived: false,
											nestable: false,
											locked: false,
											hidden: false,
											selectable: true,
											moveable: true,
											resizable: true,
											autoReplace: false,
											autoLayout: false,
											layout: {
												snap: {
													v: [],
													h: [],
												},
												left: 0,
												top: 70,
												width: 100,
												height: 30,
											},
											props: {
												content: "点我关闭",
												color: "#ffffff",
												fontSize: 16,
												fontStyle: "normal",
												fontWeight: "normal",
												lineHeight: 30,
												textAlign: "center",
												textDecorationLine: "none",
												backgroundColor: "transparent",
												borderWidth: 0,
												borderColor: "transparent",
												borderStyle: "solid",
												borderRadius: 0,
											},
											state: {},
											watchers: [],
											dataSources: [],
											actions: [
												{
													name: "action1",
													type: "none",
													changeVisibleParams: {
														targetComponentsId: [],
														visible: "toggle",
													},
													changePropParams: {
														targetComponentId: "",
														key: "",
														expression: "",
													},
													changeStateParams: {
														targetComponentId: "",
														key: "",
														expression: "",
													},
													requestDataSourceParams: {
														targetComponentId: "",
														name: "",
													},
													triggerOtherActionParams: {
														targetComponentId: "",
														name: "",
													},
													beforeHandler: 'emits("close");\nreturn true;',
													afterHandler: "",
												},
											],
											emits: {
												click: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: ["action1"],
												},
												dblclick: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
												mounted: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
												beforeUnmount: {
													executeType: "concurrent",
													timeout: 0,
													actionsName: [],
												},
											},
											customProps: [],
											customEmits: [],
											components: [],
											propsExpression: {},
											stateExpression: {},
										},
									],
								},
							],
							propsExpression: {},
							stateExpression: {},
						},
						{
							version: "0.0.1",
							id: "qm316",
							key: "text",
							title: "打开",
							actived: false,
							nestable: false,
							locked: false,
							hidden: false,
							selectable: true,
							moveable: true,
							resizable: true,
							autoReplace: false,
							autoLayout: false,
							layout: {
								snap: {
									v: [],
									h: [],
								},
								left: 0,
								top: 0,
								width: 240,
								height: 30,
							},
							props: {
								content: "预览模式下，点我打开对话框",
								color: "#ffffff",
								fontSize: 16,
								fontStyle: "normal",
								fontWeight: "normal",
								lineHeight: 30,
								textAlign: "center",
								textDecorationLine: "none",
								backgroundColor: "transparent",
								borderWidth: 0,
								borderColor: "transparent",
								borderStyle: "solid",
								borderRadius: 0,
							},
							state: {},
							watchers: [],
							dataSources: [],
							actions: [
								{
									name: "action1",
									type: "none",
									changeVisibleParams: {
										targetComponentsId: [],
										visible: "toggle",
									},
									changePropParams: {
										targetComponentId: "t2y2x",
										key: "show",
										expression: "true",
									},
									changeStateParams: {
										targetComponentId: "",
										key: "",
										expression: "",
									},
									requestDataSourceParams: {
										targetComponentId: "",
										name: "",
									},
									triggerOtherActionParams: {
										targetComponentId: "",
										name: "",
									},
									beforeHandler: "parent.components[0].props.show = true;\nreturn true;",
									afterHandler: "",
								},
							],
							emits: {
								click: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: ["action1"],
								},
								dblclick: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								mounted: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
								beforeUnmount: {
									executeType: "concurrent",
									timeout: 0,
									actionsName: [],
								},
							},
							customProps: [],
							customEmits: [],
							components: [],
							propsExpression: {},
							stateExpression: {},
						},
					],
					propsExpression: {},
					stateExpression: {},
				}))(),
			});
			this.assets.push({
				id: generateId(),
				title: "页面",
				categories: ["基础"],
				cover: pageCover,
				component: Page(),
			});
			this.assets.push({
				id: generateId(),
				title: "骨架",
				categories: ["开发"],
				cover: boneCover,
				component: Bone(),
			});
			this.assets.push({
				id: generateId(),
				title: "容器",
				categories: ["基础"],
				cover: containerCover,
				component: Container(),
			});
			this.assets.push({
				id: generateId(),
				title: "文本",
				categories: ["基础"],
				cover: textCover,
				component: Text(),
			});
			this.assets.push({
				id: generateId(),
				title: "对话框",
				categories: ["反馈"],
				cover: dialogCover,
				component: Dialog(),
			});
			this.assets.push({
				id: generateId(),
				title: "通用图表",
				categories: ["图表"],
				cover: commonChartCover,
				component: Chart(),
			});
		},
	},
});
